<template>
  <div>
    <Row style="background-color: #f8f8f9; padding: 0 10px 10px 10px;">
      <div style="width: 100%;  padding: 0.5rem; text-align: left; cursor: pointer" @click="showTextArea = !showTextArea">
        <span style="font-size: 14px;">重复采集检查(单次最多{{maxUrlNum}}条，每条一行)</span>
        <Icon type="ios-arrow-up" v-if="showTextArea" ></Icon>
        <Icon type="ios-arrow-down" v-else></Icon>
      </div>
      <div style="width: 100%; margin: 0 auto;" v-show="showTextArea">
        <Input type="textarea" v-model.trim="searchParam.urls"
               placeholder="https://detail.1688.com/offer/658789258085.html?spm=a2615.7691456.autotrace-offerGeneral.1.7819lJfslJfsh3
https://detail.1688.com/offer/657434034236.html?spm=a2615.7691456.autotrace-offerGeneral.13.7819lJfslJfsh3
https://detail.1688.com/offer/568946648447.html?spm=a2615.7691456.autotrace-offerGeneral.31.4ef4504305Yxpt"
               clearable :autosize="{minRows: 10, maxRows: 20}" ></Input>
        <Button type="primary" icon="md-search" long @click="search()" style="margin-top: 0.5rem;">检查</Button>
      </div>
    </Row>
    <List class="data-list" border header="确定重复采集的产品">
      <div v-if="list1.length > 0 || list2.length > 0">
        <ListItem v-for="(item, index) in list1" :key="item.id" class="list-item">
          <div style="width: 100%; text-align: left;">
            <KeyValueView title="采集编号" :value="item.pCode"></KeyValueView>
            <KeyValueView title="重复链接" :value="item.sourceUrl"></KeyValueView>
          </div>
        </ListItem>
        <ListItem v-for="(item, index) in list2" :key="item.id" class="list-item">
          <div style="width: 100%; text-align: left;">
            <KeyValueView title="产品SKU" :value="item.code"></KeyValueView>
            <KeyValueView title="重复链接" :value="item.url"></KeyValueView>
          </div>
        </ListItem>
      </div>
      <div v-else>
        <ListItem>
          <div style="width: 100%; text-align: center; color: #ccc;">没有发现重复采集的数据</div>
        </ListItem>
      </div>
    </List>

    <!-- 显示大图 -->
    <Modal v-model="bigImage.isShow" title="查看图片" footer-hide :width="600">
      <div class="big-img-box">
        <img :src="bigImage.src" alt="图片加载失败">
      </div>
    </Modal>

    <!-- 显示全部分类 -->
    <Modal v-model="allCategories.isShow" title="查看所有分类" footer-hide :width="600">
      <List border>
        <ListItem v-for="(item, index) in allCategories.categoryNames" :key="index" style="margin: 0; padding: 5px 10px;">
          <span class="tiy_key">{{item.join(" / ")}}</span>
        </ListItem>
      </List>
    </Modal>
  </div>
</template>

<script>
import checkData from "./js/productCheck/checkData";
import {checkProducts, initPageInfo} from "./js/productCheck/checkFuns";
import {isEmpty, isNotEmpty} from "../js/commonUtils";
import productData from "./js/product/productData";
import productData2 from "../stands/productSelect/js/productData"
import KeyValueView from "../widgets/KeyValueView";

export default {
  name: "ProductCheck",
  data() {
    return {
      showTextArea: true,
      ossPath: this.$store.getters.aliImgPrefix+"products/",
      yunPath: this.$store.getters.imgPrefix,
      searchParam: checkData.tParam.searchParam,
      list1: checkData.tData.list1,
      list2: checkData.tData.list2,
      maxUrlNum: checkData.tData.maxUrlNum,
      bigImage: {
        src: "",
        isShow: false,
      },
      allCategories: {
        isShow: false,
        categoryNames: [],
      },
      dict: productData.dict,
    }
  },
  components: {KeyValueView},
  methods: {
    search() {
      checkProducts(this);
    },
    getProductOriginalImg1(row) {
      let imgOriginal = "";
      if(row.mainImgs != null && row.mainImgs.length > 0) {
        imgOriginal = row.mainImgs[0].colorImg;
      }else if(row.colors != null && row.colors.length > 0) {
        imgOriginal = row.colors[0].colorImg;
      }
      return isEmpty(imgOriginal)?"":this.ossPath+imgOriginal;
    },
    getProductImg1(row) {
      let imgOriginal = this.getProductOriginalImg1(row);
      if(isEmpty(imgOriginal)) {
        return "";
      }
      if(this.isItemAuditing(row) || this.isItemAudited(row)) {
        let imgUrl = imgOriginal.substring(0, imgOriginal.lastIndexOf("/"))+"/200w"+imgOriginal.substring(imgOriginal.lastIndexOf("/"))
        return imgUrl;
      }
      return imgOriginal;
    },
    isItemAuditing(item) {
      return item.state == this.dict.stateAuditing;
    },
    isItemAudited(item) {
      return item.state == this.dict.stateAudited;
    },
    isItemBanned(item) {
      return item.hasBanned;
    },
    getProductOriginalImg2(item) {
      if(item.showImage == null) {
        return "";
      }
      return this.yunPath+item.showImage.originalImagePath;
    },
    getProductImg2(item) {
      if(item.showImage == null) {
        return "";
      }
      let imgUrl = "";
      if(isNotEmpty(item.showImage.zipImages)) {
        let zipImages = this.$toJson(item.showImage.zipImages);
        for(let zipImg of zipImages) {
          if(zipImg.size == "200w") {
            imgUrl = zipImg.imagePath;
            break;
          }
        }
      }

      if(imgUrl == "") {
        imgUrl = item.showImage.originalImagePath;
      }
      return this.yunPath + imgUrl;
    },
    showBigImage(imgSrc) {
      this.bigImage.src = imgSrc;
      this.bigImage.isShow = true;
    },
    getProductState(state) {
      let element = productData2.tStatus.states.find(element => state == element.value);
      return element==null?"":element.label;
    },
    getProductStateColor(state) {
      switch (state) {
        case productData2.tStatus.stateOnline:
          return "#19be6b";
        case productData2.tStatus.stateOffline:
          return "#c5c8ce";
        case productData2.tStatus.stateDeleted:
          return "#ed4014";
        case productData2.tStatus.stateNew:
          return "#2db7f5";
        default:
          return "#2db7f5";
      }
    },
    getProductWeight(item) {
      if(item.weight == null) {
        return "无";
      }
      return item.weight+'g';
    },
    getHasSizeTable(item) {
      if(item.sizeTable == null || item.sizeTable.length == 0) {
        return "无";
      }
      return "有";
    },
    getDateStr(dateTime) {
      if(dateTime == null) {
        return "";
      }
      return this.$tiyBJTime(dateTime)
    },
    hasClassified(item) {
      return item.categoryNames != null && item.categoryNames.length > 0;
    },
    viewMoreCategories(item) {
      if(this.hasClassified(item)) {
        this.allCategories.categoryNames.splice(0);
        this.allCategories.categoryNames.push(...item.categoryNames);
        this.allCategories.isShow = true;
      }
    },
  },
  mounted() {
    initPageInfo();
  }
}
</script>

<style scoped lang="less">
@import (once,optional)  "../css/base.less";
.data-list {
  margin: 1rem 0rem;
  line-height: 25px;
}
.list-item {
  .flex-colum-wrap;
    justify-items: left;
    align-items: start;
  .item-top{
    width: 100%;
    margin-bottom: 5px;
  .flex-row-wrap;
    justify-content: space-between;
  }
  .item-content {
    margin-bottom: 35px;
    text-align: left;
  }
  .item-bottom{
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    display: block;
  //padding: 0 1rem 0.5rem 0;
    cursor: pointer;
    text-align: right;
    button {
      margin-left: 0.5rem;
    }
  }
}
.big-img-box {
  width: 100%;
  min-height: 500px;
  text-align: center;
}
.big-img-box img {
  max-width: 100%;
  vertical-align: middle;
}
</style>
